home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Metrowerks Versions / C04 Speech / P05 Speech Channel / SpeechChannelIntro.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  2.3 KB  |  110 lines  |  [TEXT/MMCC]

  1. //____________________________________________________________
  2. //    SpeechChannelIntro.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Gestalt.h>
  13. #include <Speech.h>
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void           InitializeToolbox( void );
  19. Boolean        IsSpeechAvailable( void );
  20. SpeechChannel  OpenOneSpeechChannel( void );
  21.  
  22.  
  23. //____________________________________________________________
  24.  
  25. void  main( void )
  26.    OSErr          theError;
  27.    Boolean        speechPresent;
  28.    SpeechChannel  theChannel;
  29.    Str255         theString =  "\pUsing my own speech channel";
  30.    
  31.    InitializeToolbox();
  32.  
  33.    speechPresent = IsSpeechAvailable();
  34.    if ( speechPresent == false )
  35.       ExitToShell();
  36.  
  37.    theChannel = OpenOneSpeechChannel();
  38.    if ( theChannel == nil )
  39.       ExitToShell();
  40.  
  41.    theError = SpeakText( theChannel, (Ptr)(theString + 1), theString[0] );
  42.    if ( theError != noErr )
  43.       ExitToShell();
  44.  
  45.    while ( SpeechBusy() == true )
  46.       ;
  47.             
  48.    theError = DisposeSpeechChannel( theChannel );
  49.    if ( theError != noErr )
  50.       ExitToShell();
  51. }
  52.  
  53.  
  54. //____________________________________________________________
  55.  
  56. SpeechChannel  OpenOneSpeechChannel( void )
  57. {
  58.    SpeechChannel  theChannel;   
  59.    OSErr          theError;
  60.    
  61.    theError = NewSpeechChannel( nil, &theChannel );
  62.    
  63.    if ( theError != noErr )
  64.    {
  65.       theError = DisposeSpeechChannel( theChannel );
  66.       theChannel = nil;
  67.    }
  68.       
  69.    return ( theChannel );
  70. }
  71.  
  72.  
  73. //____________________________________________________________
  74.  
  75. Boolean  IsSpeechAvailable( void )
  76. {
  77.    OSErr    theError;
  78.    long     theResult;
  79.    Boolean  speechAvail;
  80.    
  81.    theError = Gestalt( gestaltSpeechAttr, &theResult );
  82.    if ( theError != noErr )
  83.       ExitToShell();
  84.       
  85.    speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );  
  86.    if ( speechAvail > 0 )
  87.       return ( true );
  88.    else
  89.       return ( false );
  90. }
  91.  
  92.  
  93. //____________________________________________________________
  94.  
  95. void  InitializeToolbox( void )
  96. {
  97.    InitGraf( &qd.thePort );
  98.    InitFonts();
  99.    InitWindows();
  100.    InitMenus();
  101.    TEInit();
  102.    InitDialogs( 0L );
  103.    FlushEvents( everyEvent, 0 );
  104.    InitCursor();
  105. }
  106.  
  107.  
  108.  
  109.